package com.movitech.mobile.cz.base.purchase.controller;


import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.purchase.entity.PSpPlanDetail;
import com.movitech.mobile.cz.base.purchase.service.PSpPlanDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * <p>
 * PSpPlanDetail 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@RestController
@RequestMapping("/v1/pSpPlanDetail")
@Api(value = "战略采购规划-需求明细基础操作接口", description = "战略采购规划-需求明细基础操作接口")
public class PSpPlanDetailController {
    @Autowired
    private PSpPlanDetailService pSpPlanDetailService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有战略采购规划-需求明细接口",
            notes = "获取所有战略采购规划-需求明细接口",
            response = PSpPlanDetail.class
    )
    public RestReturnResult list() {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PSpPlanDetail> page = pSpPlanDetailService.selectPage(new Page<PSpPlanDetail>());
        restResult.setData(page);
        return restResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "战略采购规划-需求明细列表查询接口",
            notes = "战略采购规划-需求明细列表查询接口",
            response = PSpPlanDetail.class
    )
    public RestReturnResult searchList(@RequestBody PSpPlanDetail pSpPlanDetail,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PSpPlanDetail> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(pSpPlanDetail);
        page = pSpPlanDetailService.selectPage(page,wrapper);
        restResult.setData(page);
        return restResult;
    }

    @GetMapping("/getPSpPlanDetail/{id}")
    @ApiOperation(
            value = "战略采购规划-需求明细对象ID获取接口",
            notes = "战略采购规划-需求明细对对象ID获取接口",
            response = PSpPlanDetail.class
    )
    public RestReturnResult addPSpPlanDetail(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        PSpPlanDetail pSpPlanDetail = pSpPlanDetailService.selectById(id);
        restResult.setData(pSpPlanDetail);
        return restResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "战略采购规划-需求明细添加接口",
            notes = "战略采购规划-需求明细添加接口",
            response = PSpPlanDetail.class
    )
    public RestReturnResult add(@RequestBody PSpPlanDetail pSpPlanDetail) {
        RestReturnResult restResult = RestReturnResult.success();
        pSpPlanDetailService.insert(pSpPlanDetail);
        restResult.setData(pSpPlanDetail);
        return restResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "战略采购规划-需求明细更新接口",
            notes = "战略采购规划-需求明细更新接口",
            response = PSpPlanDetail.class
    )
    public RestReturnResult update(@RequestBody PSpPlanDetail pSpPlanDetail) {
        RestReturnResult restResult = RestReturnResult.success();
        pSpPlanDetailService.updateById(pSpPlanDetail);
        restResult.setData(pSpPlanDetail);
        return restResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "战略采购规划-需求明细通过ID删除接口",
            notes = "战略采购规划-需求明细通过ID删除接口",
            response = PSpPlanDetail.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        pSpPlanDetailService.deleteById(id);
        return restResult;
    }


}

